import { Component, Injector, ElementRef, ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { BasePage } from '../basePage';
/**
 * Generated class for the TestPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-test',
  templateUrl: 'textarea.html',
})
export class TextareaPage extends BasePage {
  title = "传参过来";
  count = 0;
  model = '';
  constructor(injector: Injector) {
    super(injector);
    if (this.navParams.get('title'))
      this.title = this.navParams.get('title');

    if (this.navParams.get('str'))
      this.model = this.navParams.get('str');
    this.count = this.model.length;
  }


  ionViewDidLoad() {
    console.log('ionViewDidLoad TestPage');
  }
  /**返回上一级目录 */
  dismissCLI() {
    this.viewCtrl.dismiss(this.model);
    console.log(this.model)
  }
  dismissCLI1() {
    let data = { 'foo': 'bar' };
    this.viewCtrl.dismiss(data);
  }

  onChangeinput() {
    let len = 0;
    for (let i = 0; i < this.model.length; i++) {
      let c = this.model.charCodeAt(i);
      len++;
    }
    this.count = len;
  }


  @ViewChild('myInput') myInput: ElementRef;
  resize() {
    var element = this.myInput['_elementRef'].nativeElement.getElementsByClassName("text-input")[0];
    var scrollHeight = element.scrollHeight;
    element.style.height = scrollHeight + 'px';
    this.myInput['_elementRef'].nativeElement.style.height = (scrollHeight + 16) + 'px';
  }

  ngAfterViewInit() {
    let element = this.myInput['_elementRef'].nativeElement;
    //element.style.height =  (window.screen.height - 100) + 'px' ;//
    // this.resize();
  }
}
